﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hi_Baidu.Packet.InPacket;
using Hi_Baidu.Packet.InPacket.UpdateUserInfo;
using Hi_Baidu.Enum.User;

namespace Hi_Baidu.Packet
{
    class BasePacketListener : IPacketListener
    {
        private delegate void PUBLIC_CALL_METHOD(Object Args);

        #region IPacketListener 成员

        public bool Accpet(InPackage pck)
        {
            return pck.GetProtocol() == Protocol.NetworkProtocol.Base;
        }

        public void PackageArrived(InPackage pck)
        {
          if(Globle.user.USER_ONLINE_STATE != ONLIN_STATE.OFFLINE)
          {
              switch (pck.Command)
              {
                  //登陆回馈包
                  case Protocol.IN_NetworkCommand.REPLY_LOGIN_PACKAGE:
                      PackageProcess.Process_REPLY_Login_Package(new LoginReplyPacket(pck));
                      break;
                  //获取自身信息回馈包
                  case Protocol.IN_NetworkCommand.REPLY_GETMYSELFINFO_PACKAGE:
                      PackageProcess.Process_REPLY_GETMYSELFINFO_PACKAG(new GetMySelfInfo_ReplyPacket(pck));
                      break;
                  //获取自身分组信息回馈包
                  case Protocol.IN_NetworkCommand.REPLY_GROUP_PACKAGE:
                      PackageProcess.Process_REPLY_GROUP_PACKAGE(new GetGroupReplyPacket(pck));
                      break;
                  //获取指定分组下好友的信息回馈包
                  case Protocol.IN_NetworkCommand.REPLY_FRIEND_BY_GROUPID_PACKAGE:
                      PackageProcess.Process_REPLY_FRIEND_BY_GROUPID_PACKAGE(new GetFriendByGroupIdReplyPacket(pck));
                      break;
                  //获取指定好友详细信息回馈包
                  case Protocol.IN_NetworkCommand.REPLY_GET_FRIENDINFO_PACKAGE:
                      PackageProcess.Process_REPLY_FRIEND_INFO_PACKAGE(new GetFriendInfoReplyPacket(pck));
                      break;
                  //获取修改个性签名信息回馈包
                  case Protocol.IN_NetworkCommand.REPLY_MODIFY_PROD_PACKAGE:
                      PackageProcess.Process_REPLY_MODIFYPROD_PACKAGE(new ModifyProdReplyPacket(pck));
                      break;
                  case Protocol.IN_NetworkCommand.REPLY_UPDATE_USERINFO:
                      switch (pck.GetType())
                      {
                          //回馈更新昵称请求包
                          case "ReplyUpdateChanageNickName":
                              PackageProcess.Process_UPDATE_USERINFO_PACKAGE(new UpdateUserNickNameReplyPacket(pck));
                              break;
                          //回馈更新个性签名请求包
                          case "ReplyUpdateChanageProd":
                              PackageProcess.Process_UPDATE_USERINFO_PACKAGE(new UpdateUserProdReplyPacket(pck));
                              break;
                          //回馈更新姓名请求包
                          case "ReplyUpdateChanageName":
                              PackageProcess.Process_UPDATE_USERINFO_PACKAGE(new UpdateUserNameReplyPacket(pck));
                              break;
                          //回馈更新性别请求包
                          case "ReplyUpdateChanageSex":
                              PackageProcess.Process_UPDATE_USERINFO_PACKAGE(new UpdateUserSexReplyPacket(pck));
                              break;
                          //回馈更新电话请求包
                          case "ReplyUpdateChanageTel":
                              PackageProcess.Process_UPDATE_USERINFO_PACKAGE(new UpdateUserTelReplyPacket(pck));
                              break;
                          //回馈更新电子邮箱请求包
                          case "ReplyUpdateChanageEmal":
                              PackageProcess.Process_UPDATE_USERINFO_PACKAGE(new UpdateUserEmailReplyPacket(pck));
                              break;
                          //回馈更新密码请求包
                          case "ReplyUpdateChanagePassword":
                              PackageProcess.Process_UPDATE_USERINFO_PACKAGE(new UpdateUserPasswordReplyPacket(pck));
                              break;
                          case "ReplyUpdateChanageHeadImage":
                              PackageProcess.Process_UPDATE_USERINFO_PACKAGE(new UpdateUserHeadImageReplyPacket(pck));
                              break;
                      }
                      break;
                  //强制下线包
                  case Protocol.IN_NetworkCommand.SET_USER_OFFLINE:
                      PackageProcess.Process_User_Set_Offline(new SetOfflinePacket(pck));
                      break;
                  //回馈更改用户在线状态请求包
                  case Protocol.IN_NetworkCommand.REPLY_CHANAGE_USER_ONLINE_STATE_PACKAGE:
                      PackageProcess.Process_REPLY_CHANAGE_USER_ONLINESTATE(new ChanageUserOnlineStateReplyPacket(pck));
                      break;
                  //回馈更新用户分组请求包
                  case Protocol.IN_NetworkCommand.REPLY_UPDATE_ITEM_PACKAGE:
                      PackageProcess.Process_REPLY_UPDATE_ITEM(new UpdateItemReplyPacket(pck));
                      break;
                  //回馈添加用户分组请求包
                  case Protocol.IN_NetworkCommand.REPLY_ADD_NEW_ITEM_PACKAGE:
                      PackageProcess.Process_REPLY_ADD_NEW_ITEM(new AddItemReplyPacket(pck));
                      break;
                  //回馈删除用户分组请求包
                  case Protocol.IN_NetworkCommand.REPLY_DELETE_ITEM_PACKAGE:
                      PackageProcess.Process_REPLY_DELETE_ITEM(new DeleteItemReplyPacket(pck));
                      break;
                  //回馈获取要添加好友信息请求包 - 没有找到该好友
                  case Protocol.IN_NetworkCommand.REPLY_GET_POST_FRIEND_INFO_NOT_FIND_PACKAGE:
                      PackageProcess.Process_REPLY_GET_POSTFRIENDINFO_NOT_FIND(new GetPostFriendInfoNotFind_ReplyPacket(pck));
                      break;
                  //回馈获取要添加好友信息请求包
                  case Protocol.IN_NetworkCommand.REPLY_GET_POST_FRIEND_INFO:
                      PackageProcess.Process_REPLY_GET_POSTFRIENDINFO(new GetPostFriendInfo_ReplyPacket(pck));
                      break;
                  //处理转发的好友申请
                  case Protocol.IN_NetworkCommand.REDIRECT_ADD_FRIEND:
                      PackageProcess.Process_REDIRECT_ADD_FRIEND(new RedirectAddFriendPacket(pck));
                      break;
                  //处理添加好友结果发送成功回馈包
                  case Protocol.IN_NetworkCommand.REPLY_RETURN_POST_ADD_FRIEND_PACKAGE:
                      PackageProcess.Process_RETURN_POST_ADD_FRIEND_RESULT(new PostAddFriendResultReplyPacket(pck));
                      break;
                  //处理回馈添加好友最终状态的广播信息包
                  case Protocol.IN_NetworkCommand.REPLY_BOARDCAST_ADD_FRIEND:
                      PackageProcess.Process_BOARDCAST_ADD_FRIEND(new BoardCast_AddFriendReplyPacket(pck));
                      break;
                  //处理好友上线信息包
                  case Protocol.IN_NetworkCommand.BOARDCAST_USERONLINE_MESSAGE:
                      PackageProcess.Process_BOARDCAST_USERONLINE_MESSAGE(new Boardcast_UserOnlinePacket(pck));
                      break;
                  //处理回馈删除好友信息包
                  case Protocol.IN_NetworkCommand.REPLY_DELETE_FRIEND_PACKAGE:
                      PackageProcess.Process_DeleteFriend(new DeleteFriendReplyPacket(pck));
                      break;
                  //处理回馈用户心跳请求包
                  case Protocol.IN_NetworkCommand.REPLY_USER_HEART_BREATH_PACKAGE:
                      PackageProcess.Process_REPLY_USER_HEART_BREATH(new UserHeartBreathReplyPacket(pck));
                      break;
              }
          }
        }
        #endregion
    }
}
